package pkg.genericity.controllers;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pkg.genericity.business.BeanBO;
import pkg.genericity.utils.BeanUtil;

public class BeanEntryController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public BeanEntryController() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    	if (request.getSession().getAttribute("beanclass") !=null) {
    		Object object = new BeanUtil().getPopulatedBean(request.getSession().getAttribute("beanclass").toString(), request.getParameterMap());

    		BeanBO Objectbo = new BeanBO();

    		if (Objectbo.addBean(object))  {

    			response.getWriter().write("successfully added <br><a href=''>Home Page</a>");
    		} else {
    			response.getWriter().write("Failed adding Object <br><a href=''>Home Page</a>");
    		}
    	}
    	else {
    		response.getWriter().write("Failed adding Object <br><a href=''>Home Page</a>");
    	}
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
